package com.compty.paint.manager;

import java.util.Date;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.compty.core.hibernate.HibernateEntityDao;
import com.compty.core.page.Page;
import com.compty.paint.domain.TransactionRecord;
import com.compty.security.domain.User;

/**
 * 结算记录
 * @author 朱庆辉
 */
public class TransactionRecordManager extends  HibernateEntityDao<TransactionRecord>{

	public Page queryForPage(Integer curPage, Integer pageSize, User userInfo,
			Date startDate, Date endDate, String filterTxt, String filterValue) {
		// TODO Auto-generated method stub
		   Criteria criteria =  super.createCriteria();
			  
	        criteria.addOrder(Order.desc("id"));
	        
	        if(userInfo!= null && "0".equals(userInfo.getAdministratorFlag())){
	        	  criteria = criteria.add(Restrictions.eq("userId", userInfo.getId()));
	        }
	        
	        if(startDate != null){
	        	 criteria = criteria.add(Restrictions.ge("deal_time", startDate));
	        }
	        
	        if(endDate != null){
	        	 criteria = criteria.add(Restrictions.lt("deal_time", endDate));
	        }

	        if ((filterTxt != null) && (filterValue != null)&& (!filterTxt.equals("")) && (!filterValue.equals(""))) {
	            criteria = criteria.add(Restrictions.like(filterTxt,
	                        "%" + filterValue + "%"));
	        }
	        
	        Page page = super.pagedQuery(criteria, curPage, pageSize);
	        
	        return page;
	}

}
